<?php 
	error_reporting(-1);
	class Db{
		private $hostName;	
		private $userName;
		private $userPass;
		private $userDb;
		private $Db;
		public function __construct($hostName, $userName, $userPass, $userDb){
			$this->hostName = $hostName;
			$this->userName = $userName;
			$this->userPass = $userPass;
			$this->userDb 	= $userDb;
			$this->Db = new mysqli($this->hostName, $this->userName, $this->userPass, $this->userDb);
			if(false == $this->Db){
				echo "Db Links Error";
			}
		}
		
		public function query($sql){
			$queryObj = $this->Db->query($sql);
			return $this->_stmt($queryObj);
		}
		
		public function findId($tableId){
			$this->tableIdInput = $tableId;
			if(!is_array($this->tableIdInput)){
				$this->tableId = $this->tableIdInput;
			}else{
				foreach($this->tableIdInput as $values){
					$this->tableId.= "`".$values."`,";	
				}
				
				$this->tableId = substr($this->tableId, '0', '-1');
			}
			return $this;
		}

		public function table($tableName){
			$this->tableName = $tableName;
			return $this;
		}
		
		public function where($condition){
			$this->conditionInput = $condition;
			if(!is_array($this->conditionInput)){
				$this->condition = 'WHERE '.$this->conditionInput;
			}else{
				foreach($this->conditionInput as $values){
				
				}
			}
			return $this;
		}
		
		
		public function limit($limit){
			if(!isset($limit)){
				$limit = null;
			}else{
				$limit = $limit;
			}
			
			$this->limitInput = $limit;
			if(!is_array($this->limitInput)){
				$this->limit = $this->limitInput;
			}else{
				foreach($this->limitInput as $values){
					$this->limit .= $values;
				}
			}
			return $this;
		}
		
		
		public function order($order){
			$this->orderIpnut = $order;			
			$this->order = $this->orderIpnut;
			return $this;
		}
		
		
		private function _stmt($queryObj){
			while($result = $queryObj->fetch_assoc()){
				$resultObj[] = $result;	
			}
			return $resultObj;
		}
				
		public function select(){			
			if(!isset($this->condition)){
				$this->condition = null;
			}
			if(!isset($this->limit)){
				$this->limit = null;
			}
			
			if(!isset($this->tableId)){
				$sql = "SELECT * FROM".' `'.$this->tableName.'` '.$this->condition;	
			}else{
				$sql = "SELECT ".$this->tableId." FROM".' `'.$this->tableName.'` '.$this->condition.' '.'ORDER BY'.' '.$this->order.' '.'LIMIT'.' '.$this->limit;	
			}
			echo $sql;
			$sql = addslashes($sql);
			$queryObj 	= $this->Db->query($sql);
			if(false == $queryObj){
				echo "SQL Statement Error!!!";
				exit();
			}
			return $this->_stmt($queryObj);
		}	

	}

	
	
	$Db = new Db('192.168.1.7', 'huxiaofei', 'a5B123T', 'scout');
	$data = $Db->table('trxn_payment')->findId(array('resmsg','cctype'))->where('trxn_type = 10')->limit('15, 15')->order('ID desc')->select();
	//$data = $Db->table('taxi_company')->findId(array('Id','company_name'))->where('Id=3 OR Id =4')->select();
	//$sql = "select * from taxi_company where Id=2";
	//$data = $Db->query($sql);
	echo "<pre>";
	print_r($data);
	
	
	
	
